<?php

class App_Util_Botones {
	
	private $botones;
	private $actual = "";
	function __construct() {
		$this->botones = array ();
	}
	
	function agregar($texto_boton, $pagina_enlace, $parametros = "") {
		$this->botones [$texto_boton] ["url"] = $pagina_enlace;
		$this->botones [$texto_boton] ["param"] = $parametros;
		$this->botones [$texto_boton] ["check"] = "No";
		$this->botones [$texto_boton] ["actual"] = "No";
	}
	
	
	function eliminar($texto_boton) {
		unset ( $this->botones [$texto_boton] );
		if ($this->actual == $texto_boton)
			$this->actual = "";
	}
	
	function checkear($texto_boton) {
		$this->botones [$texto_boton] ["check"] = "Si";
	}
	
	function actual($texto_boton) {
		$this->actual = $texto_boton;
	}
	
	function renderElement($orientacion="") {
		$baseUrl = Zend_Controller_Front::getInstance ()->getBaseUrl();
		$arr_keys = array_keys ( $this->botones );
		$botonActual = 0;
		$tituloTabla="";
		if("vertical"==$orientacion){
			$inicioTabla="<table class=\"buttons buttonsV vertical\">\n";
			$finTabla="</table>";
			$inicioBoton="<tr><td>";
			$finBoton="<td></tr>\n";
		}else{
			$inicioTabla="<div align=\"right\"><div class=\"btn-group\">";
			$finTabla="</div></div>";
			$inicioBoton="";
			$finBoton="\n";
			
			$sesionTabBoton = new Zend_Session_Namespace("TABBOTON");
			$titulo=$sesionTabBoton->NombreBotonH;
			if(!empty($sesionTabBoton->NombreBotonV)){
			    $titulo.=" :: ".$sesionTabBoton->NombreBotonV;
			}
		    if(!empty($sesionTabBoton->NombreBotonH)){
		        $tituloTabla="<div align='left'><h2>{$titulo}</h2></div>";
		    }
		}
		
		$menuBoton = $inicioTabla;

		for($i = 0; $i < count ( $this->botones ); $i ++) {
			$parametros = $this->botones [$arr_keys [$i]] ["param"];
			$url = $this->botones [$arr_keys [$i]] ["url"];
			$actual = $this->botones [$arr_keys [$i]] ["actual"];
			$checkeado = $this->botones [$arr_keys [$i]] ["check"];
			if ($parametros != "") {
				$url .= "{$parametros}";
			}
			$classActual="";
			if (($actual == "Si") || ($this->actual == $arr_keys [$i])) {
				$botonActual = $i;
				$classActual=" btn-info";
			}
			$imagencheckeado="";
			if("Si"==$checkeado){
				$imagencheckeado=" <span class=\"glyphicon glyphicon-ok\"></span> ";
			}
			if ($url != "#") {
				$menuBoton .= "{$inicioBoton}<a class=\"btn btn-default btn-sm{$classActual}\" href=\"{$baseUrl}{$url}\">{$imagencheckeado}{$arr_keys[$i]}</a>{$finBoton}";
			} else {
				$menuBoton .= "{$inicioBoton}<a class=\"btn btn-default btn-sm disabled\" href=\"#\">{$imagencheckeado}{$arr_keys[$i]}</a>{$finBoton}";
			}
		}
		$menuBoton .= "{$finTabla}{$tituloTabla}";
		return $menuBoton;
	}
}

?>